const e = require('express')
const express=require('express')

let app =express()
app.use(express.static('.'))
app.use(express.urlencoded({

    extended:false
}))
app.use(express.json())
app.get('/',(req,res)=>{
    res.json('hi')
})
data={
    sno:'07200823',
    name:'',
    gender:1,
    skill:[
        {
        name:'HTML',
        count:0
        },
        {
            name:'CSS',
        count:0 
        },
        {
            name:'miniprogram',
            count:0
        },
        {
            name:'JAVASCRIPT',
            count:0
        }
    ],
    satisfaction:0,
    opinion:'',
    count:0

}
app.get('/sampledata',(req,res)=>{
    res.json(data)
})
app.post('/sampledata',(req,res)=>{
    console.log(req.body)
    data.skill.forEach(v=>{
        req.body.skill.indexOf(v.name)>-1?v.count++:''
    })
    data.satisfaction=(data.satisfaction*data.count+req.body.satisfaction)/(data.count+1)
    data.count++
    data.name=req.body.name
    data.opinion+=req.body.name+':'+req.body.opinion+'\n'
    res.json(data)
})

app.listen(9999)